<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<link href="${basePath}/static/css/Pigeonhole/Pigeonhole_list.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="${basePath}/static/css/medicalRecord_Search/medicalSearch.css"/>
<script type="text/javascript" src="${basePath}/static/publics/assets/jqPaginator/jqPaginator.js"></script>
<div class="list_NR">
        <div class="loc">
            <h3>病案编页</h3>
            <ul class="loc_loc">病案查询 > 编页查询
            </ul>
        </div>
        
        <div class="list_con_table">
            <input type="hidden" value="${medRecordQuery.totalCounts }" id="totalCountsHidden">
			 <form action="${basePath}/medrecord/queryPaginationMedrecordImage" method="get" id="queryForm">
	        	<div class="search_table">
                <ul class="clearfix" style="margin-bottom:0;">
                    <li class="Label_1" style="width:12%">姓名：&nbsp;</li>
                    <li class="Label_2" style="width:17%"><input class="input_box" type="text"  name="name" id='name' value='${medRecordQuery.name }' /></li>
                    <li class="Label_1" style="width:12%">身份证：&nbsp;</li>
                    <li class="Label_2" style="width:17%"><input class="input_box" type="text"  name="idCard" id='idCard' value='${medRecordQuery.idCard}' /></li>
                    <li class="Label_1" style="width:12%">出院日期：&nbsp;</li>
                    <li class="Label_2" style="width:30%">
                    	<input style="width:40%;" class="input_box" name="outHospitalStartDate" id="outHospitalStartDate" value="<fmt:formatDate value="${medRecordQuery.outHospitalStartDate}" pattern="yyyy-MM-dd"/>" onfocus="WdatePicker()" type="text"> 
                   - <input style="width:40%" class="input_box" name="outHospitalEndDate" id="outHospitalEndDate" value="<fmt:formatDate value="${medRecordQuery.outHospitalEndDate}" pattern="yyyy-MM-dd"/>" onfocus="WdatePicker()" type="text">
                    <%-- <input class="input_box" type="text"  name="outHospitalDate" id='' value='<fmt:formatDate value="${medRecordQuery.outHospitalDate}" pattern="yyyy-MM-dd"/>' onfocus="WdatePicker()"/> --%></li>
                    <li class="Label_1" style="width:12%">ID号：&nbsp;</li>
                   <li class="Label_2" style="width:17%"><input class="input_box" type="text" id="mrId"  name="mrId" value='${medRecordQuery.mrId}' /></li>
                 	<li class="Label_1" style="width:12%">住院次数：&nbsp;</li>
                    <li class="Label_2" style="width:17%"><input class="input_box" type="text"  name="visitNumber" id='visitNumber' value='${medRecordQuery.visitNumber}' /></li>
                  	<input type="hidden" name="orderType" id='orderType' value="${medRecordQuery.orderType}">
                
                	<input type="hidden" name="currentPage"  value="${medRecordQuery.currentPage}"> 
                  	 <li class="Label_1" style="width:12%">编页状态：&nbsp;</li>
                    <li class="Label_2" style="width:30%">
                    	
                    	<c:choose>
                    		<c:when test="${medRecordQuery.paginationStatus==null or medRecordQuery.paginationStatus==1}">
                    			<input type="radio" class="radio_cl" name='paginationStatus' checked="checked"  value='1' />未编页&nbsp;&nbsp;
                    			<input type="radio" class="radio_cl" name='paginationStatus'  value='2' />已编页
                    		</c:when>
                    		<c:otherwise>
                    			
                    			<input type="radio" class="radio_cl" name='paginationStatus'  value='1' />未编页&nbsp;&nbsp;
                    			<input type="radio" class="radio_cl" name='paginationStatus' checked="checked"  value='2' />已编页
                    			
                    		</c:otherwise>
                    	</c:choose>
                    	
    					
                    <li class="Label_5">
                        <div class="right">
                        	<input class="btn" type="submit" value="查询">
                        </div>
                    </li>
                </ul>
            </div>
	        </form>
			 
			 <form action="${basePath}/medrecord/queryPaginationMedrecordImage" method="get" id="pageForm">
	        	<input type="hidden" name="currentPage" value="${medRecordQuery.currentPage }" id="currentPageHidden">
	        	<input type="hidden" name="pageSize" value="${medRecordQuery.pageSize }" id="pageSizeHidden">
	        	<input  type="hidden"  name="visitNumber" id='' value='${medRecordQuery.visitNumber}' />
	        	<input  type="hidden"  name="name" id='' value='${medRecordQuery.name}' />
	        	<input  type="hidden"  name="idCard" id='' value='${medRecordQuery.idCard}' />
	        	<input  type="hidden"  name="outHospitalStartDate" id='' value='<fmt:formatDate value="${medRecordQuery.outHospitalStartDate}" pattern="yyyy-MM-dd"/>' /> 
	        	<input  type="hidden"  name="outHospitalEndDate" id='' value='<fmt:formatDate value="${medRecordQuery.outHospitalEndDate}" pattern="yyyy-MM-dd"/>' /> 
	        	<input type="hidden" name="mrId" id='' value="${medRecordQuery.mrId}">
	        	<input type="hidden" name="orderType" id='hiddenOrderType' value="${medRecordQuery.orderType}">
	        	<input type="hidden" name="paginationStatus"  value="${medRecordQuery.paginationStatus}">
	        </form>

        </div>
       
        <table class="Search_tableList" cellpadding="0" cellspacing="0">
     
            <tr>
                <td class="tdLabel_4">姓名</td>
                <td class="tdLabel_4">身份证号</td>
                <td class="tdLabel_4">ID号</td>
                
                <td class="tdLabel_4">出院日期</td>
                <td class="tdLabel_4"><a class="int" onclick="orderByType(this)" data-order-type="${medRecordQuery.orderType}">住院次数</a></td>
                <td class="tdLabel_4">是否编页</td>
                 <td class="tdLabel_4">扫描者</td>
                <!--  <td class="tdLabel_4">所属医院</td> -->
                <td class="tdLabel_4">操作</td>
            </tr>
            
           
            <tbody id="tbody">
            	<c:forEach var="med" items="${hospitalizationNotes }">
            		<tr>
            			
            			<td class='tdLabel_5'>${med.name}</td>
            			<td class='tdLabel_5'>${med.id_number}</td>
            			<td class='tdLabel_5'>${med.mr_id}</td>
            			<td class='tdLabel_5'><fmt:formatDate value="${med.out_hospital_date}" pattern="yyyy-MM-dd"/></td>
            			<td class='tdLabel_5'>${med.visit_number}</td>
            			<td class='tdLabel_5'>${med.isPage==1?'未编页':'已编页'}</td>
            			<td class='tdLabel_5'>${med.operator}</td>
            			<%-- <td class='tdLabel_5'>${med.hospital_name }</td> --%>
            			<td class='tdLabel_5'>
            				<%-- <a class="int" target="_blank" href="${basePath}/medrecord/paginationMedrecordShow?firstGuid=${med.first_level_medical_guid}" >编页预览</a> --%>
            				<%-- <a class="int" target="_blank" onclick="picPage(this)" first_guid="${med.first_level_medical_guid}" href="${basePath}/medrecord/paginationMedrecordImages?firstGuid=${med.first_level_medical_guid}" >病案编页</a> --%>
							<a class="int" target="_blank" onclick="picPage(this)" first_guid="${med.first_level_medical_guid}" >病案编页</a>
            			</td>
            		</tr>
            	</c:forEach>
            </tbody>
               
           
        </table>


        <div class="pageList">
            <ul class="pagination clearfix" id="page_plus"></ul>
            <div class="pagination">
                <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
            </div>
        </div>
    </div>
 <script type="text/javascript" src="${basePath}/static/publics/assets/My97DatePicker/WdatePicker.js"></script>
 <script type="text/javascript">
	$(function(){
		//$("#mrId").focus();
		var totalCounts = $("#totalCountsHidden").val();
		var pageSize = $("#pageSizeHidden").val();
		var currentPage = $("#currentPageHidden").val();
		initPage(parseInt(totalCounts),parseInt(pageSize),parseInt(currentPage));
	});
	
	function orderByType(obj){
		var $this = $(obj);
		var orderType = $this.attr("data-order-type");
		orderType=orderType=="asc"?"desc":"asc";
		$("#hiddenOrderType").val(orderType);
		$("#orderType").val(orderType);
		$this.attr("data-order-type",orderType);
		$("#queryForm").submit();
		
	}
	
	
	//病案编页
	function picPage(obj){
		var $this =$(obj);
		var firstGuid = $this.attr("first_guid");
		var name = $("#name").val();
		var idCard = $("#idCard").val();
		var outHospitalStartDate = $("#outHospitalStartDate").val();
		var outHospitalEndDate = $("#outHospitalEndDate").val();
		var mrId =$("#mrId").val();
		var visitNumber = $("#visitNumber").val();
		var currentPage = $("#currentPageHidden").val();
		
		var paginationStatus = $("input[name='paginationStatus']:checked").val();
		//alert(name+"--"+idCard+"---"+outHospitalStartDate+"--"+outHospitalEndDate+"--"+mrId+"---"+visitNumber);
		window.location.href = "${basePath}/medrecord/paginationMedrecordImages?firstGuid="+firstGuid+"&name="+name+"&idCard="+idCard+"&outHospitalStartDate="+outHospitalStartDate+"&outHospitalEndDate="+outHospitalEndDate+"&mrId="+mrId+"&visitNumber="+visitNumber+"&currentPage="+currentPage+"&paginationStatus="+paginationStatus;
		
	}
	
	
	$("#mrId").change(function(){
		var $this=$(this);
		var inentity=$this.val();
		if(inentity!=null && inentity!='' && inentity!=undefined){
			if(isContainMark(inentity)){
				var mrId=inentity.split("-")[0];
				var visitNumber=inentity.split("-")[1];
				
				if(!isNumber(visitNumber)){
					alert("请重新扫描条形码");
					$("#mrId").val("").focus();
					$("#visitNumber").val("");
					
					return;
				}
				
				$("#mrId").val("").val(mrId);
				$("#visitNumber").val("").val(visitNumber);
				$("#queryForm").submit();
			}
		}
	});
	
	function isNumber(value) {
	    var patrn = /^[0-9]*$/;
	    if (patrn.exec(value) == null || value == "") {
	        return false
	    } else {
	        return true
	    }
	}
	
	
	function isContainMark(inentity){
		var reg = RegExp(/-/);
		return reg.test(inentity);
	}
	
	
	function initPage(totalCounts,pageSize,currentPage){
		 var visiblePages = 5;
		 var totalPages = totalCounts%pageSize==0?(totalCounts/pageSize):(parseInt(totalCounts/pageSize)+1);
		 $('#page_plus').jqPaginator({
                totalCounts: totalCounts,
		        pageSize:pageSize,
		        visiblePages: visiblePages,
		        currentPage: currentPage,

		        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
		        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
		        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
		        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
		        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
		        onPageChange: function (num,type) {

		     		if(type !='init'){
		     			$("#currentPageHidden").val(num);
						$("#pageSizeHidden").val(pageSize);
						$("#pageForm").submit();
					}
		            $("#totalPage").html(totalCounts);
		            $("#currentPage").html(num+"/"+totalPages);
		            $("#currentPageHidden").val(currentPage);
				    $("#pageSizeHidden").val(pageSize);
		        }
		    });

	}
</script>